package com.gfxy.modules.index.service;

import com.gfxy.modules.index.mapper.DepartmentIndexMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: lijixin 2021/9/14 11:32 上午
 */
@Service
public class DepartmentIndexService {

    @Autowired
    private DepartmentIndexMapper departmentIndexMapper;

    public Map<String,String> getTotalClasstimeByYear(String year, String orgCode){
        List<Map> queryList = departmentIndexMapper.selectClasstimeByYear(year,orgCode);
        Map<String,String> result = new HashMap<>();
        if(queryList.size() ==1){
            Map map = queryList.get(0);
            result.put("average",map.get("average").toString());
            result.put("teacherCount",map.get("teacherCount").toString());
            result.put("total",map.get("total").toString());
        } else {
            result.put("average","0");
            result.put("teacherCount","0");
            result.put("total","0");
        }
        return result;
    }

    public Map<String,List> getTeacherRankByYear(String year, String orgCode){
        List<String> teacherNames = new ArrayList<>();
        List<Double> teacherClasstimes = new ArrayList<>();
        List<Map> list = departmentIndexMapper.selectTeacherRankByYear(year,orgCode);
        for (Map map : list) {
            teacherNames.add(map.get("realname").toString());
            teacherClasstimes.add(Double.valueOf(map.get("total").toString()));
        }

        Map<String,List> result = new HashMap<>();
        result.put("names",teacherNames);
        result.put("classtimes",teacherClasstimes);
        return result;
    }
}
